import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:vdrag_saas/list/pages/home/home_tab.dart';
import 'package:vdrag_saas/product_detail.dart';
import 'package:go_router/go_router.dart';

void main() {
  runApp(const MyApp());
  // runApp(GlobalState(
  //   isMobile: true, // 初始化全局变量
  //   child: MyApp(),
  // ));
}
final GoRouter _router = GoRouter(
  routes: <RouteBase>[
    GoRoute(
      path: '/',
      builder: (BuildContext context, GoRouterState state) {
        return const HomeTab();
      },
    ),
    GoRoute(
      name: 'productDetail',
      path: '/product/detail/:id',
      builder: (BuildContext context, GoRouterState state) {
        var paths = state.pathParameters;
        return ProductDetail(paths['id']);
      },
    ),
  ],
);
class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    // Size screenSize = MediaQuery.of(context).size;
    // double screenWidth = screenSize.width;
    // bool isMobile = DeviceUtil.isMobile || screenWidth < 600;
    // GlobalState.of(context).setState(isMobile);

    return MaterialApp.router(
      title: '星图金能应用商城',
      routerConfig: _router,
      theme: ThemeData(
        // This is the theme of your application.
        //
        // TRY THIS: Try running your application with "flutter run". You'll see
        // the application has a purple toolbar. Then, without quitting the app,
        // try changing the seedColor in the colorScheme below to Colors.green
        // and then invoke "hot reload" (save your changes or press the "hot
        // reload" button in a Flutter-supported IDE, or press "r" if you used
        // the command line to start the app).
        //
        // Notice that the counter didn't reset back to zero; the application
        // state is not lost during the reload. To reset the state, use hot
        // restart instead.
        //
        // This works for code too, not just values: Most code changes can be
        // tested with just a hot reload.
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        scaffoldBackgroundColor: const Color(0xfff1f1f1),
        useMaterial3: true,
        textTheme: const TextTheme(
          bodyMedium: TextStyle(fontFamily: '思源黑体'),
          bodySmall: TextStyle(fontFamily: '思源黑体'),
          bodyLarge: TextStyle(fontFamily: '思源黑体')
        )
      ),
      scrollBehavior: MyCustomScrollBehavior(),
    );
  }
}

class MyCustomScrollBehavior extends MaterialScrollBehavior {
  @override
  Set<PointerDeviceKind> get dragDevices => {
        PointerDeviceKind.touch,
        PointerDeviceKind.mouse,
      };
}
